/* R. J. Cano, rev. Aug 19 2014

Dear reader:

Greetings.

Welcome to A243106;

Briefly here are exposed some facts about this sequence
after a fast review of some underlying notions and conceptions.

We hope you find both interesting and useful this material.

1) The definition or title:

This is basically a list of values, for "the partial sums
of the integer powers of 10 taking as negative those with
prime exponents".

Let be here a(n)=A243106(n); Then for example:

a(1)=(+1)*10^1, since 1 is NOT a prime.
a(2)=a(1)+(-1)*10^2, since 2 is a prime.
a(3)=a(2)+(-1)*10^3, since 3 is also a prime.
a(4)=a(3)+(+1)*10^4, since 4 is NOT a prime.
.
.
.

And so on.

Therefore we have a quite simple recurrence relation:

a(0)=0
a(n)=a(n-1)+chi(n)*10^n, for any n>0 where:

chi(n)={+1 if n is NOT a prime, -1 otherwise}

For example in PARI-GP we can express it as:

chi=n->(-1)^isprime(n);

Therefore by combining these ideas in a single
expression, we have:

a(n)=sum{k=1..n} ( (-1)^isprime(n) ) * 10^n;

Now notice that in terms of algorithmic performance
such procedure might become significantly slow,
so in order to do some "optimization" there,
we notice that the preceding sum is identical to:

"Sum everything taken as positive and then subtract
twice the sum of all what originally was negative";

Indeed this is a general principle, you can verify
it with other kind of sums not necessarily the def.
given here for a(n);

It is justified the usage of the PARI-GP forprime()
loop there at PROG in the sequence entry.

2) What is actually "10"? (The first induction)

Nowadays in the 21th century we have the common habit
of associating directly the English word "ten", the
written symbol "10" or the concatenation of "1" and "0",
and the abstract concept of "ten units", which is a
way of classifying all the discrete sets that can be
coordinated matching all their elements in pairs, when
these sets are composed by ten elements. What actually
happens there is that we had invented a written symbol,
and an spoken word associated, establishing such kind
of pairs (symbol,word) for dealing with discrete sets,
their cardinal numbers, and those elementary operations
now logically natural and familiar to us (Notice however
that people like George Cantor and Bertrand Russel among
others for example invested long time during their
lives in the contemplation of these matters).

The elementary arithmetic arisen and all what we take
today for correct and safe, have such subtlety that
it is interesting to delve in, and perhaps it will be
so always.

This sequence perhaps might be a good example of how
to present evidences and arguments in favor of
stating that the integer numbers (such human
abstractions) still hiding beautiful patterns,
algorithms and simplicity.

3) The positional number systems: We always have "10"
   symbols for writing down all the numbers.
   
   (Second induction)
   
Ask someone to write all the numbers he/she was taught as
the first and more important Ones at the Elementary
School.

After some time, he/she invariably will tell you: 1,2,3,4,
....,19,20;

Do you notice something curious there?. Indeed, people not
quite familiar to Sciences and Engineering often avoid the
usage the zero and the negative numbers. Of course!, while
less rules or conventions we need to keep in mind it is
better for us.

Bingo!, again the conception of simplicity in terms of
quantity and not much in quality is a key principle here.

In order to be able of writing down any number, we only
need "10" different symbols. These symbols nowadays named
either digits or letters, in Spanish sometimes "Guarismos",
for the decimal number system or base 10 (our worldwide
standard for human trading, books, newspaper and so on)
are:

{0,1,2,3,4,5,6,7,8,9}

Do you notice it?,

You don't have an unique symbol for writing down "ten"
as number. In order to express "ten" you have to combine
"1" and "0".

Please imagine a space shuttle launching TV broadcast,
at the final moments of the event, someone gives a
spoken countdown. Well let us repeat such countdown
from "ten", by writing at the left of each word, one
of the elements in the previous list:

9) "ten",
8) "nine",
7) "eight",
6) "seven",
5) "six",
4) "five",
3) "four",
2) "three",
1) "two",
0) "one".

This what we have done is to coordinate the set
of ten words with the set of ten "digits" for
decimal or base 10. we can do that in 3628800 or 10!
different ways. The present one is helpful for
illustration of the following:

If we rank the list above the first is not "1" but "0"
instead, the second is not "2" but "1" instead, and so
on until we reach the tenth that is not... written!!!

"ten" written as number was not part of our countdown.

But the tenth digit inside our ranking is "9" instead.

Ok. It is a little bit, or all a mess. What actually is
important is to keep the calm and think in the following
conceptually abstract "leap":

Let be "b" a special number named "base" which tells us
how many digits or individual symbols we have available
for writing numbers. Then we cannot write b using just
a symbol, but we write "10" instead, because when we
decided to include the zero associating to it an
individual symbol "0", (b-1) symbols left available.

Therefore 0 is the first, and is 1 the second, but
by defining an operation named "addition" consisting
in finding out the cardinal for the union of two given
sets, let us says bags of candy of variable sizes, then
we have notably: Whether one of those bags is empty
or not. If empty, we say that it has "Zero", writing "0".

If we have a bag with "x" candies, and join it to another
with "y" candies, then we obtain the arithmetic sum x+y as
result.

If one of them were zero, let us say y=0, then

x+y=x+0=x so, when joining the content of those bags, we obtain
x candies as result. Such special case is the addition with
the neutral element (by describing it with the jargon from the
Group Theory).

If we have a bag of x candies and another bag with y
peanuts then this time we are in presence of an algebraic
addition or polynomials addition, a little bit more complicated
set of rules that applies, but there still existing a neutral element
and the Group Theory does still applying there.

In the further things like (b-1) will be considered as polynomials until
a particular value of b is explicitly specified, and then it will be
replaced (b-1) with its evaluation.

We have the zero "0" as neutral element for the addition,
the unit "1" as neutral element for the product or multiplication,

(neutral in the sense of leaving unchanged what is operated)

The combination of both as "10" is called "the base" of a positional
number system. It will have the main purpose of having alternatively
the meaning of any positive integer number greater than the unit, specifying
by this way the quantity individual elements: namely "ciphers", "digits", or
"letters" that we will have available for writing numbers.

Some popular examples (Omnipresent in the CS and Engineering):

Binary:

b=2 and the digits/ciphers/letters are two {0,1}

Octal and Hexadecimal (also denoted simply "HEX")

b=8 for Octal and the digits/ciphers/letters are eight {0..7}

b=16 for Hexadecimal and the digits/ciphers/letters
     are sixteen {0..9,A=ten,B=eleven,C=twelve,D=thirteen,E=fourteen,15=fifteen}
	 
	 For example "(10-1)*10" in Hexadecimal corresponds to: (16-1)*16 = 15*16
     240 in decimal, or simply "F0", indeed the analogue for "ninety" in decimal.

CONSEQUENCE: Every arithmetical expression based upon the unit "1" and
			 the base "10" will have alternatively infinitely many associated
			 results or meanings depending on the choice of the meaning for
			 "10".

For example:

i) "10" itself.

ii) "10-1", "(10-1)*10", ...

iii) Please see the experimental proposal at the end of this file.


(implicit) CONVENTION: Please notice that we have used there "quotes", as an
					   aid for distinguishing between the possible interpretation
					   described as a "consequence", and the actual decimal value
					   that probably associate here immediately: (10-1)*10 = 9*10 = 90.
				
Excepting when quotes are used, these "undetermined" expressions will be
written replacing "10" with a variable, for example "b" like in:


(b-1)*b as replacement for "(10-1)*10";


4) The absolute values of the terms belonging A243106
   and a proposal for their study.
   
   (Third induction)

For a given b, this sequence must be expressed at least in base b in order to
appreciate the following: Interpreting b>2 as the radix for a positional number
system, apparently every term is the concatenation of the unit with four kind
of basic elements: (b-2), (b-1), b, and (b-1)*b;

Indeed each term is the concatenation of One of these and some of the preceding
terms (See LINKS for an example illustrating this).

For b=3, the basic elements for concatenations would be: The unit, (b-2)=1
(a duplicate),(b-1)=2, b=3, (b-1)*b=6, but notice that 3 and 6 cannot be written
as single letters/digits in base 3, so 3 is "10" and such 6 actually refers to "20"
both in base 3. Therefore when b=3, this sequence refers to those numbers in
base 3 such that they are a very particular concatenation of "1"s, "2"s, "10"s,
and "20"s. The point here is that when b is interpreted as the radix or base for a 
positional number system, any digit or letter "y" in such base satisfies
0<=y<=(b-1) and y*b which in decimal is simply that, in base b must be written
as "y0", similarly y*(b^2) as "y00" and so on (By convention replacing y with
other symbols if y were greater than decimal ten, like it is used to do for
example in Hexadecimal).

In base 3 a main difference is that each term might have more "1"s than the
corresponding term by offset in the other bases. Therefore it will fail a test
verifying that each letter/digit "1" for a term in base 3 have the same place
in the corresponding term for another bases. The reciprocal comparison won't
fail since where an "1" is placed inside a term for any base b>3, the
corresponding term in base 3 have "1" at the same place.

For b=10, we have the unit "1" and the set {"8","9","10","90"} the first three
terms are a(1)=10, a(2)=-90, a(3)=-1090, and the absolute value for each next
term is the concatenation of some of these elements and the absolute value for
some of the preceding terms.

Notice if b=2 were included: Due the four basic elements there are
(b-2)=0, (b-1)=1, b=10 (Binary), (b-1)*b=10 (Binary), some terms would
come with leading zeros, those that usually are omitted, therefore a test
or comparison for detecting whether two sequences have the same number of 
digits would fail. However it could be done a successful comparison instead:
If the terms of any sequence for b>2 are modified by replacements of the 
corresponding basic elements and the leading zeros are deleted. For example 
from b=10 or decimal: By replacing 90 with 10, 9 with 1 (here the order is
important), 8 with 0, and then by deleting every leading zero it is obtained
the sequence for b=2.

Here is not included the concatenation algorithm, merely proposing its existence
and dependence on the prime numbers (by definition). Such hypothetical algorithm
would be appreciated in terms of importance from the following observation: If
it were replaced at the definition for chi(k) the condition prime/not-prime by 
odd/even, then the 5 basic elements described here would be reduced to 3:
(b-1), b, and (b-1)*b (The unit alone and (b-2) wouldn't be present and the 
concatenation patterns would be quite less complicated).

5) The "first differences" of A243106 resembles the same kind of already
   observed patterns for A243106 itself.
   
   (Fourth induction)
   
Well, not exactly. This depends on what we understand by "first differences".

Whether we mean a(n+1)-a(n), or a(n+1) - ( a(n+1) DIV a(n) )*a(n);

( Provided that "DIV" means "integer division" )

Here in the present work, we would be referring to the "integer division" variant
of the definition for "first differences".

The observed pattern can be described as follows: "for some b the described kind
of first differences expressed in base b shares a common structure in the same
way than the original sequence does it, and some sort of incremental concatenations
patterns also is present there in a similar way to the original sequence".

A sample test of this can be found by browsing the plain-text file at:

https://oeis.org/w/images/5/52/WoOW_0001.txt


------------------------------------------------

Source code: Programming in PARI-GP for
this sequence.

Remarks

Dear reader:

1) Please notice that here is strongly focused
   the attention in the absolute values for
   these terms.

2) You also can load this as a GP-PARI script.

3) Below in the further, for simplicity a(n)
   was replaced with abs(a(n)). You're encouraged
   to try those tests shown below in another ways.

-----------------------------------------------

Observations.

Nested/concatenated terms. Patterns dictionary:

1) The patterns are named in lexicographic order
   of appearance.

2) The replacements should be made according the
   length of the patterns, shortest patterns first.
   
3) Define more patterns if necessary.

Given x=10 a positive integer (Specifically 10 for OEIS).


By replacement priority, the patterns are listed below:

Warning: The following choice of symbols is a little
bit unfortunate since they might be misinterpreted as
Hexadecimal digits. Please keep in mind the context.

D=x=10
E=(x-1)*x=90

A=D/D=1
B=(E-D)/D=8
C=E/D=9

{1}=DE
{2}=BCD
{3}=C{1}
{4}=E{2}
{5}=E{3}
{6}=E{4}
{7}={1}{4}
{8}=A{7}
{9}=BBE{5}
{10}=C{8}
{11}=E{9}
{12}=E{10}
{13}={1}{10}
{14}=A{13}
{15}=BBE{11}
{16}=C{14}
{17}=E{15}
{18}=E{16}
{19}={1}{16}
{20}=A{19}
{21}=BBE{17}
{22}=C{20}
{23}=D{22}
{24}=A{23}
{25}=A{24}
{26}=A{25}
{27}=BBBBE{21}
{28}=C{26}
{29}=E{27}
{30}=E{28}
{31}={1}{28}
{32}=A{31}
{33}=A{32}
{34}=A{33}
{35}=BBBBE{29}
{36}=C{34}
{37}=D{36}
{38}=A{37}
{39}=BBE{35}
{40}=C{38}
{41}=E{39}
{42}=E{40}
{43}={1}{40}
{44}=A{43}
{45}=BBE{41}
{46}=C{44}
{47}=D{46}
{48}=A{47}
{49}=A{48}
{50}=A{49}
{51}=BBBBE{45}
{52}=C{50}
{53}=A{52}
{54}=A{53}
{55}=A{54}
{56}=A{55}
{57}=BBBBE{51}
{58}=C{56}
{59}=E{57}
{60}=E{58}
{61}={1}{58}
{62}=A{61}
{63}=A{62}
{64}=A{63}
{65}=BBBBE{59}
{66}=C{64}
{67}=D{66}
{68}=A{67}
{69}=BBE{65}
{70}=C{68}
{71}=E{69}
{72}=E{70}
{73}={1}{70}
{74}=A{73}
{75}=A{74}
{76}=A{75}
{77}=BBBBE{71}
{78}=C{76}
{79}=D{78}
{80}=A{79}
{81}=BBE{77}
{82}=C{80}
{83}=D{82}
{84}=A{83}
{85}=A{84}
{86}=A{85}
{87}=BBBBE{81}
{88}=C{86}
{89}=D{88}
{90}=A{89}
{91}=A{90}
{92}=A{91}
{93}=A{92}
{94}=A{93}
{95}=BBBBBBE{87}
{96}=C{94}
{97}=D{96}
{98}=A{97}
{99}=BBE{95}
{100}=C{98}
{101}=E{99}
{102}=E{100}
{103}={1}{100}
{104}=A{103}
{105}=BBE{101}
{106}=C{104}
{107}=E{105}
{108}=E{106}
{109}={1}{106}
{110}=A{109}
{111}=BBE{107}
{112}=C{110}
{113}=D{112}
{114}=A{113}
{115}=A{114}
{116}=A{115}
{117}=A{116}
{118}=A{117}
{119}=A{118}
{120}=A{119}
{121}=A{120}
{122}=A{121}
{123}=A{122}
{124}=A{123}
{125}=BBBBBBBBBBBBE{111}
{126}=C{124}
{127}=D{126}
{128}=A{127}
{129}=BBE{125}
{130}=C{128}
{131}=D{130}
{132}=A{131}
{133}=A{132}
{134}=A{133}
{135}=BBBBE{129}
{136}=C{134}
{137}=E{135}
{138}=E{136}
{139}={1}{136}

...And so on.

For example, "{11}=E{9}" should be read as:

"Pattern #11 is (by definition) the concatenation of patterns E and #9".

The purpose is to encode any given sample composed with the first M terms of
this sequence in the form:

D, E, {1}, {2}, {3}, ...., {k}

This is, like a simple enumeration in increasing order of the defined patterns.

Question:
Which would be the semi-numerical algorithm underlying to this sequence,
based on this replacements scheme?

*/

ap(n,x)={my(s);forprime(p=1,n,s+=x^p);s}
a(n,x=10)={abs((x^(n+1)-1)/(x-1)-2*ap(n,x)-1)}

/* Extension: Aug 7 2014 */

av(n,x,y=x)=digits(a(n,x),y); /* Digits of a(n,x) "when it is expressed in base y" 
                               (Be careful!, perhaps it should be always y>=x) */
fixMe(i,B)=if(i>=B,B-1,i);

letter(i)=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"][fixMe(i,36)+1];

aStr(n,x=10,y=x)={my(s="",w=av(n,x,y));for(j=1,#w,s=Str(s,letter(w[j])));s}

/* Deletes leading character given by str1[1], str1[2], ... from  str2 (recursive version) */
leadingChrDel(str1,str2,index=1)={my(ans="",V0=Vecsmall("0"),V1=Vecsmall(str1),V2=Vecsmall(str2),j);while(V2[j++]==V1[index],);while(j<=#str2,ans=Str(ans,letter(V2[j]-V0[1]));j++);if(index==#str1,ans,leadingChrDel(str1,ans,index+1))};

demo(terms=2500)={

sample002=vector(terms,j,aStr(j,2));  \\ Binary
sample003=vector(terms,j,aStr(j,3));  \\ Base 3
sample004=vector(terms,j,aStr(j,4));  \\ Base 4
sample008=vector(terms,j,aStr(j,8));  \\ Octal 
sampleDef=vector(terms,j,aStr(j));    \\ By default: Decimal or Base10
sample012=vector(terms,j,aStr(j,12)); \\ Duodecimal
sample016=vector(terms,j,aStr(j,16)); \\ Hexadecimal

\\ From Base 4 onward, terms with the same offset must have identical lengths in digits/letters.
\\ sampleDef is taken as reference ("cmp" stands for "comparison"). 

\\ It is expected that this comparison fails for Binary: Since there

\\ are less basic elements (less than 4, just 2, "0" and "1").
\\ (For Base 3 apparently it should fail, but observe there that One of the basic elements
\\ actually is duplicated)

\\ This initial obvious comparison proves that the test works fine.

cmpDef=(#sampleDef==#sampleDef)*prod(j=1,#sampleDef,#sampleDef[j]==#sampleDef[j]);

if(cmpDef,print("\n\nThe proposed comparison makes sense and works."),print("\n\nHey!: Something is wrong here.");quit());

\\ The expected fail.

cmp002=(#sampleDef==#sample002)*prod(j=1,#sampleDef,#sampleDef[j]==#sample002[j]);

\\ The empirical* verification of the observed and PRESUMABLY GENERAL properties.
\\ (*Note: Not exhaustive at all)

cmp003=(#sampleDef==#sample003)*prod(j=1,#sampleDef,#sampleDef[j]==#sample003[j]);
cmp004=(#sampleDef==#sample004)*prod(j=1,#sampleDef,#sampleDef[j]==#sample004[j]);
cmp008=(#sampleDef==#sample008)*prod(j=1,#sampleDef,#sampleDef[j]==#sample008[j]);
cmp012=(#sampleDef==#sample012)*prod(j=1,#sampleDef,#sampleDef[j]==#sample012[j]);
cmp016=(#sampleDef==#sample016)*prod(j=1,#sampleDef,#sampleDef[j]==#sample016[j]);

/* By having in account the leading zeros problem with x=2 or binary */

sampleDefAltered=vector(terms,j,leadingChrDel("8",sampleDef[j]));
cmp002again=(#sampleDefAltered==#sample002)*prod(j=1,#sampleDefAltered,#sampleDefAltered[j]==#sample002[j]);

answer=(!cmp002)*cmp003*cmp004*cmp008*cmp012*cmp016*cmp002again;

print("\n\n\n\n...Done!.\n\nConclusion. Are we right relative to our initial & informal description for this seq.?: "if(answer,"Yes.","Nope!, Oops."));

}

/*
  Final comment/invitation from the author:
  
  <<Let me propose briefly the following experiment based on the comments on this sequence.
    It can be done without none line of code nor specialized hardware. Titled "Live LAB":
  
  Just pick a scientific calculator with capabilities for basic arithmetic in other popular
  positional systems like binary, octal, and hexadecimal (I have a CASIO FX-570ES that can
  do that). You cannot type there "abs(10^1-10^2-10^3+10^4-10^5+10^6-10^7)" in Hexadecimal,
  but you can type this other expression instead:
  
  "10-10*10-10*10*10+10*10*10*10-10*10*10*10*10+10*10*10*10*10*10-10*10*10*10*10*10*10"
  
  please ensure that the +/- sings and repeated "10*"s are correct and then hit "=";
  You'll get "F0F0EF10" in the answer and... it is wrong!, but wait, just press the 
  key for displaying such same number in Decimal and you'll find that there still 
  being pending to apply the absolute value. There is shown "-252645616" In decimal,
  so multiply what is displayed by -1, and go back to hexadecimal by hitting the proper
  key. Now it is shown "0F0F10F0", and by replacing E with 8 and F with 9 it will looks
  like "09091090", precisely abs(a(7)) at the data field or in the b-file... (i) Now repeat
  it in the other available bases excepting binary and base-3, (ii) Then try the same procedure with
  other terms>>.

  ...That's all for now. - EOF */